



router.post("/upload", async (req, res) => {
  let form = new multiparty.Form();
  form.uploadDir = "upload";

  form.parse(req, async (err, fields, files) => {
    if (err) {
      return res.status(400).send({ code: 400, message: "文件解析失败" });
    }

    try {
     
      const commentPath = "http://127.0.0.1:3000/" + files.img[0].path; // 获取头像文件路径 // 更新用户头像路径

      

      return res.send({
        code: 200,
        message: "上传成功",
        data,
      });
    } catch (error) {
      console.error("更新数据库失败:", error);
      return res.status(500).send({ code: 500, message: "服务器内部错误" });
    }
  });
});
